package com.so206.controller;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.servlet.http.HttpServletRequest;

/**
 * HTTP 错误处理
 */
@Controller
public class HttpErrorController implements ErrorController {


    @Override
    public String getErrorPath() {
        return "/error";
    }

    /**
     * 错误处理
     */
    @RequestMapping("/error")
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public String handle(HttpServletRequest request, Model model) {
        model.addAttribute("ecc", "请求的页面不存在或无权限访问!");
        return "404";
    }

}
